package com.szh.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;


// @Order(-1)
// @Component
public class AuthFilter implements GlobalFilter {
    
    // @Resource
    // SysUserFeignApi sysUserFeignApi;
    /**
     * 处理当前请求，有必要的话，将请求交给下一个过滤器
     * @param exchange 请求上下文，里面可以获取 request response 等
     * @param chain 下一个过滤器链
     * @return
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest newRequest = exchange
                .getRequest()
                .mutate()
                .build();
        ServerWebExchange newExchange = exchange.mutate().request(newRequest).build();
        // if (!sysUserFeignApi.isLogin()){
        //     ServerHttpResponse response = exchange.getResponse();
        //     return response.writeWith(Mono.just(response.bufferFactory().wrap("eee".getBytes())));
        // }
        return chain.filter(newExchange);

    }
}
